<template>
    <div class="slba-container">
        <div class="slba-header">
            <CommonHeader   leftIcon title="操作" />
        </div>
        <div class="slba-content">
            <div class="slba-bazxx">
                <div class="slba-bazxx-title">
                    备案者信息
                </div>

                <van-field rows="1" autosize type="textarea" center v-model="filingMain.FilingEnterpriseName"
                    label="备案者" class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.FilingEnterpriseCode"
                    label="统一社会信用代码" class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.LinkmanDomicile" label="住所"
                    class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.LocationsRegion"
                    label="种子生产经营区域" class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.FilingPrincipalName" label="负责人"
                    class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.LinkmanPhone" label="联系电话"
                    class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.FilingNumber" label="流水号"
                    class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.SeedEnterpriseName"
                    label="上级企业名称" class="my-field" readonly>
                </van-field>
                <van-field rows="1" autosize type="textarea" center v-model="filingMain.SeedEnterpriseCode"
                    label="社会统一信用代码" class="my-field" readonly>
                </van-field>
            </div>


            <van-form>

                <van-list class="my-list">

                    <van-cell-group v-for="(item, index) in filingMain.filingProductDTOList" :key="index"
                        class="my-list-item">
                        <!-- {{ item }} -->

                        <van-field v-model="item.VarietyName" class="my-field-variety" center readonly clickable
                            @click="onSelect(item, index)">
                            <template #left-icon>
                                <div>
                                    <van-icon v-if="item.IsChoose == 1" :name="selectImg" />
                                    <van-icon v-else :name="selectUnImg" />
                                </div>
                            </template>
                            <template #label>
                                <div class="my-input-variety">
                                    {{ item.sChoose }}
                                    {{ item.varietyName }}
                                </div>
                            </template>
                            <template #input>
                            </template>
                        </van-field>
                        <van-field v-model="item.cropID" label="作物种类" class="my-field" readonly>
                        </van-field>
                        <van-field v-model="item.varietyType" label="种子类别" class="my-field" readonly>
                        </van-field>

                        <van-field v-model="item.productionArea" label="生产面积" class="my-field" readonly>
                            <template #input>
                                <div class="my-input">
                                    {{ item.productionArea }} 亩
                                </div>
                            </template>
                        </van-field>
                        <van-field v-model="item.productionDetailRegion" label="生产地点" class="my-field" readonly>
                        </van-field>
                        <van-field label="起止年度" class="my-field" readonly>
                            <template #input>
                                <div class="my-input">
                                    {{ item.beginYear }} 至 {{ item.endYear }}
                                </div>
                            </template>
                        </van-field>
                        <van-field v-model="item.seedCompanyName" label="种子企业" class="my-field" readonly>

                        </van-field>
                        <van-field v-model="item.licenseNo" label="许可证号" class="my-field" readonly>

                        </van-field>
                        <van-cell-group>
                            <van-field label="所选地块" type="text" class="my-field" is-link readonly
                                @click="onSelectDikuai(item, index)">
                                <template #input>
                                    <div>
                                        <span v-if="item.choiceLandName">
                                            {{ item.choiceLandName.join(',') }}
                                        </span>
                                        <span v-else>
                                            暂无</span>
                                    </div>
                                </template>
                            </van-field>
                        </van-cell-group>

                    </van-cell-group>

                </van-list>

                <div class="my-qita">
                    <van-field label="其他材料" class="my-field" readonly>
                        <template #input>
                            <div>

                                <ImageSeleteView class="margin-top-12" :maxCount="100" :isEdit="false"
                                    :files="filingMain.FilesUrl" />
                            </div>
                        </template>
                    </van-field>
                </div>

            </van-form>
        </div>

        <div v-if="isShouli" class="slba-footer">

            <div class="my-buttons">
                <van-button type="primary" color="linear-gradient(to right, #FFE3DC, #FFEDE3)" round block
                    style="height: 40px; margin: 0 10px;color:#FF670B;" @click="outerVisible = true">驳回</van-button>
                <van-button type="primary" color="linear-gradient(to right, #00BF87, #25F0A0)" round block
                    style="height: 40px;color:#FFFFFF" @click="onSubmit(1, '')">通过</van-button>
            </div>
        </div>
        <el-dialog v-model="outerVisible" title="退回原因" width="90%">
            <el-input type="textarea" v-model="outerText"></el-input>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="outerVisible = false">取消</el-button>
                    <el-button type="primary" @click="onSubmit(2, outerText)">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup>
import "@/assets/css/tabs.css"
import { ref, onMounted, watch, nextTick } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { BeiAnTypeEnum, getBeiAnType } from '@/bean/BeiAnType';
import selectImg from '@/assets/img/main/select_round.png';
import selectUnImg from '@/assets/img/main/select_round_un.png';
import ImageSeleteView from "@/components/ImageSeleteView.vue";
import uiUtil from "@/util/UiUtil.js";

const router = useRouter();
const route = useRoute();
const id = uiUtil.ref(route.query.id);
const filingMain = uiUtil.ref({

})
const isEdit = uiUtil.ref(false);
const isShouli = uiUtil.ref(false);
const outerText = uiUtil.ref('');
const outerVisible = uiUtil.ref(false);

const onSelect = (item, index) => {
    if (isShouli.value) {
        if (item.IsChoose == 1) {
            item.IsChoose = 0
        } else {
            item.IsChoose = 1
        }
    }
};
onMounted(() => {
    getDataList();
})

const getDataList = async () => {
    const params = {
        FilingID: id.value,
    }
    uiUtil.http().getObj({
        url: uiUtil.urlPath.getFilingDetail,
        data: params,
        start: () => {
            uiUtil.toastLoading()
        },
        succeed: (res) => {
            // loading.value = false;
            // debugger
            console.log('1ucceed=', res)
            if (!res || !res.code || 200 != res.code) {
                uiUtil.toastFail(res.msg)
                return
            }
            filingMain.value = res.data
            let userInfo = JSON.parse(localStorage.getItem('user'))

            isShouli.value = userInfo &&
                (userInfo.RegManageRegionID == filingMain.value.AcceptanceRegionID
                    || userInfo.NewCountyRegionID == filingMain.value.AcceptanceRegionID)
                && filingMain.value.FilingStatus == 1



        },
        failed: (res) => {
            // debugger
            console.log('failed=', res)
            // showFailToast('添加失败')
            uiUtil.toastFail('添加失败')
        },
        finish: () => {
            uiUtil.toastClose()
        }
    })
};
const onSubmit = (type, text) => {
    outerVisible.value = false
    const params = {
        filingId: id.value,
        reason: text,
        type: type,
        singleAceeptVarietyDataDTOList: [],
    }

    let isSelect = false;
    filingMain.value.filingProductDTOList.forEach(element => {
        isSelect = isSelect || element.IsChoose == '1'
        params.singleAceeptVarietyDataDTOList.push({
            IsChoose: element.isChoose,
            SeedManageOrProductFilingID: element.SeedProductionFilingID,
        });
    });
    if (type == 1 && !isSelect) {
        uiUtil.toastFail('请选择受理品种')
        return
    }
    uiUtil.http().postObj({
        url: uiUtil.urlPath.beianAccept,
        data: params,
        start: () => {
            uiUtil.toastLoading()
        },
        succeed: (res) => {
            // loading.value = false;
            // debugger
            console.log('1ucceed=', res)
            if (!res || !res.code || 200 != res.code) {
                uiUtil.toastFail(res.msg)
                return
            }
            if (type == 1) {
                uiUtil.toastSuccess("受理成功");
            } else if (type == 2) {
                uiUtil.toastSuccess("驳回成功");
            }
            back()

        },
        failed: (res) => {
            // debugger
            console.log('failed=', res)
            uiUtil.toastFail('失败')
        },
        finish: () => {
            // uiUtil.toastClose()
        }
    })
}
const back = () => {
    router.back();
}
</script>

<style lang="less" scoped>
.slba-container {
    background: url('@/assets/img/main/all_bg.png') no-repeat;
    background-size: cover;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.slba-header,
.slba-footer {
    flex: 0 0 auto;
    text-align: center;
    padding: 0;
}

.slba-content {
    flex: 1 1 auto;
    overflow-y: auto;
}

.slba-bazxx {
    margin: 0 12px;
    background-color: #fff;
    border-radius: 4px;
}

.slba-bazxx-title {
    margin: 0 12px;
    padding: 16px 0 14px 0;
    font-size: 16px;
    font-weight: bold;
    color: #222;
    border-bottom: 1px solid #ededed;
}

.my-field {
    --van-field-input-text-color: #888;
    --van-field-label-color: #222;
}

.my-list-item {
    margin: 12px 12px 0 12px;
    border-radius: 4px;
}

.my-field-variety {
    font-weight: 500;
    font-size: 14px;
    color: #222;
    text-align: center;
    background-color: transparent;
}

.my-qita {
    background-color: #fff;
    margin: 12px;
    border-radius: 4px;
}

.margin-left-4 {
    margin-left: 4px;
}

.w-65-h-80 {
    width: 65px;
    height: 80px;
}

.my-buttons {

    display: flex;
    margin: 12px 16px;
}
</style>